<template>
  <div id="center">
    <div class="up">
      <div class="bg-color-black item" v-for="item in titleItem" :key="item.title">
        <p class="ml-3 colorBlue fw-b">{{item.title}}</p>
        <div>
          <dv-digital-flop :config="item.number" style="width:100%;height:.626rem;" />
        </div>
      </div>
    </div>
    <div class="down">
      <div class="percent bg-color-black" style="height: 4.075rem ; display: grid">
        <div class="ranking " style="width:100% ; height: 1.725rem">
          <span style="color:#5cd9e8">
          <icon name="chart-pie"></icon>
          </span>
          <span class="fs-xl text mx-2 mb-1">实时功率</span>
          <dv-digital-flop class="colorYellow"  :config="power"
                           style="width:100%;height:1.625rem;padding-left: 0.1rem;padding-right: 0.15rem" />
        </div>
        <dv-decoration-9
            style="height: 1.85rem; width: 1.85rem ; margin-bottom: 3.25rem;font-size:20px;justify-self: center;align-self: center;" >{{ratioPower}}%</dv-decoration-9>
      </div>
      <div class="ranking bg-color-black" style="height: 4.075rem ;">
        <span style="color:#5cd9e8">
          <icon name="align-left"></icon>
        </span>
        <span class="fs-xl text mx-2 mb-1">部门年度用电排行榜</span>
        <dv-scroll-ranking-board :config="ranking" style="height:3.75rem" />
      </div>
    </div>
  </div>
</template>

<script>
// import CenterChart from "@/components/echart/center/centerChartRate";

export default {
  props: {
    chartData: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      power: {
        number: [0],
        toFixed: 2,
        content: '{nt}KW',
        style:{
          fill: '#aa9003'
        }
      },
      ratioPower: 0,
      titleItem: [
        {
          title: "今年累计用电量",
          number: {
            number: [0],
            toFixed: 2,
            content: "{nt}"
          },
          style: {
            fontSize: 10
          }
        },
        {
          title: "本月累计用电量",
          number: {
            number: [0],
            toFixed: 2,
            content: "{nt}"
          }
        },
        {
          title: "今日累计用电量",
          number: {
            number: [0],
            toFixed: 2,
            content: "{nt}"
          }
        }],
      ranking: {
        data: [],
        carousel: "single",
        unit: "度"
      }
    };
  },
  components: {
    // CenterChart
    // centerChart1,
    // centerChart2
  },
  mounted() {
  },
  methods: {
    getDepts(yearDepts)
    {
      const array = []
      for (const dept of yearDepts) {
        const d = {
          name: dept.dept.name,
          value: dept.energy
        }
        array.push(d)
      }
      return array
    }
  },
  watch: {
    chartData: {
      handler(newData) {
        // const devices = newData.device
        console.log('energy:::',newData)
        const content = newData.content
        // const energy = newData.energy
        // const deptDevices = newData.deptDevice
        let totalPower = 0
        let ratePower = 0
        // for (const device of devices){
        //   totalPower += device.power;
        //   ratePower += device.device.ratedPower
        // }
        totalPower = content.totalPower
        ratePower = content.powerRate
        this.power = {
          number: [totalPower/1000],
          toFixed: 2,
          content: '{nt}KW',
          style:{
            fill: '#aa9003'
          }
        }
        this.ratioPower = parseInt(ratePower)
        this.titleItem = [
          {
            title: "今年累计用电量",
            number: {
              number: [content.yearEnergy],
              toFixed: 2,
              content: "{nt}"
            },
            style: {
              fontSize: 10
            }
          },
          {
            title: "本月累计用电量",
            number: {
              number: [content.monthEnergy],
              toFixed: 2,
              content: "{nt}"
            },
            style: {
              fontSize: 10
            }
          },
          {
            title: "今日累计用电量",
            number: {
              number: [content.todayEnergy],
              toFixed: 2,
              content: "{nt}"
            },
            style: {
              fontSize: 10
            }
          }]
        this.ranking= {
          data: this.getDepts(content.yearDepts),
          carousel: "single",
          unit: "度"
        }
      },
      immediate: true,
      deep: true
    }
  }
};
</script>

<style lang="scss" scoped>
.colorYellow {
  color: yellowgreen;
}
#center {
  display: flex;
  flex-direction: column;
  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .item {
      border-radius: 0.0625rem;
      padding-top: 0.2rem;
      margin-top: 0.1rem;
      width: 32%;
      height: 0.875rem;
    }
  }
  .down {
    padding: 0.07rem 0.05rem;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 3.1875rem;
    justify-content: space-between;
    .bg-color-black {
      border-radius: 0.0625rem;
    }
    .ranking {
      padding: 0.125rem;
      width: 49%;
    }

    .percent {
      width: 50%;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 50%;
        height: 1.5rem;
        span {
          margin-top: 0.0875rem;
          display: flex;
          justify-content: center;
        }
      }
      .water {
        width: 100%;
      }
    }
  }
}
</style>
